package com.example.graphqlserver;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 配置跨域策略
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
            .allowedMethods("GET", "POST", "PUT", "DELETE")  // 允许的HTTP方法
            .allowedHeaders("*")  // 允许所有头部信息
            .allowCredentials(true)  // 允许发送Cookie信息
            .maxAge(3600);  // 预检请求的缓存时间（秒）
    }
}
